<?php 
/**************************************************/
## Class Name - Model_TRADE (Contains all the functions related trade modules)
## Created By - Techmodi (24/05/2012)
/**************************************************/
class Model_LEAD_MESSAGE extends Database
{	
	function Model_LEAD_MESSAGE() {			
		$this->lead_messages = LEAD_MESSAGES;
		$this->users = USERS;
		$this->Database();
	}
	
	/****************************************************/
	// for add trade
	function addMessages($array) {
		$this->InsertData($this->lead_messages, $array);
		$insertId = mysql_insert_id();
		return $insertId;
	}
	
	function getMessages($leadid,$trade_id,$job_owner_id)
	{
		$sql = "select m.* from $this->lead_messages m INNER JOIN $this->users as tr ON m.trade_id = tr.id INNER JOIN $this->users as lo ON m.job_owner_id = lo.id WHERE m.lead_id=$leadid AND m.trade_id=$trade_id AND m.job_owner_id =$job_owner_id ORDER BY m.created DESC";

		$messages = $this->loadObjectList($sql);
		return $messages;	
	}
	function getMessageDetail($id)
	{
		$sql= "select * from $this->lead_messages where id=$id";
		return $this->loadObject($sql);	
	}
}
?>